<?php
/**
 * Created by PhpStorm.
 * User: ming
 * Date: 17-8-17
 * Time: 下午3:19
 */
$lock=new swoole_lock(SWOOLE_MUTEX);
echo "创建互坼锁 \n";
$lock->lock();
if (pcntl_fork()>0){
    sleep(1);
    $lock->unlock();
}else{
    echo "子进程 等待锁 \n";
    $lock->lock();
    echo  "子进程 获取锁 \n";
    $lock->unlock();
    exit("子进程退出 \n");
}

echo  "主进程 释放锁 \n";
unset($lock);
sleep(1);
echo "子进程退出 \n";